package com.zhx.basis.乱七八糟;

import com.google.common.collect.Lists;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class B extends A {


    public void b() {
        System.out.println("子类 b====");
    }

    public static void main(String[] args) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        int i = Runtime.getRuntime().availableProcessors();//获取到服务器的cpu内核
        executor.setCorePoolSize(5);//核心池大小
        executor.setMaxPoolSize(100);//最大线程数
        executor.setQueueCapacity(1000);//队列程度
        executor.setKeepAliveSeconds(1000);//线程空闲时间
        executor.setThreadNamePrefix("tsak-asyn");//线程前缀名称
        executor.initialize();

        List<CompletableFuture<String>> completableFutures=new ArrayList<>();
        List<String>  list=new ArrayList<>();

        list.add("111");
        list.add("111");
        list.add("111");
        list.add("111");
        list.add("111");
        list.add("111");
        list.add("111");

        List<String>  list2=new ArrayList<>();


        List<List<String>> partition = Lists.partition(list, 3);
        for (List<String> strings : partition) {

            completableFutures.add(CompletableFuture.supplyAsync(() ->{
                list2.addAll(strings);
                return null;
            },executor ));
        }

        List<String> collect = completableFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());

        System.out.println(collect);
    }
}
